<template class="container">
    <div class="header">
        <div>图块编辑器</div>
        <div class="close-btn" onclick=CloseWindow></div>
    </div>
    <Blockly ref="blockly" class="blockly" 
        v-bind:language="language or 'SystemLuaBlock'" 
        v-bind:OnGenerateBlockCodeBefore="OnGenerateBlockCodeBefore"
        v-bind:OnGenerateBlockCodeAfter="OnGenerateBlockCodeAfter"
        OnlyGenerateStartBlockCode=true 
        IsGenerateDebugInfo=true></Blockly>
</template>

<script type="text/lua">
local BlocklyEl = nil;

-- 组件解析完成
function OnReady()
    BlocklyEl = GetRef("blockly");

    _G.GetCode = function()
        local rawcode, prettycode = BlocklyEl:GetCode();
        return string.gsub(prettycode, "\t", "    ");
    end

    _G.GetXml = function()
        local xmlNodeText = BlocklyEl:SaveToXmlNodeText();
        return xmlNodeText;
    end

    BlocklyEl:LoadFromXmlNodeText(_G.xmltext);
end

local function GetCode()
    if (not BlocklyEl) then return end
    local rawcode, prettycode = BlocklyEl:GetCode();
    return rawcode;
end

function OnClickRun()
    if (type(rawget(_G, "OnRun")) == "function") then _G.OnRun(GetCode()) end
end


</script>

<style>
.container {
    height: 100%; 
    width: 100%; 
    background-color: #00000080;
    color: #ffffff;
}

.header {
    height: 40px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0px 20px;
}

.close-btn {
    width: 22px; 
    height: 22px; 
    background-color: #e6e6e6;
    background: url(Texture/Aries/Creator/keepwork/ggs/dialog/guanbi_22X22_32bits.png#0 0 22 22);
}

.close-btn:hover {
    background-color: #ffffff;
}

.blockly {
    position: absolute; 
    left: 2px; 
    right: 2px; 
    top: 40px; 
    bottom: 2px;
}
</style>
